﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
/// <summary>
///  Text拓展 打印机效果 和文字上飘效果
/// </summary>
[RequireComponent(typeof(UIType))]
public class UITextExtension : Text
{
 
#if UNITY_EDITOR
    [MenuItem("GameObject/UI/TextEx")]
    static void CreateTextEx(MenuCommand menuCmd)
    {
        // 创建游戏对象
        float w = 160f;
        float h = 30f;
        GameObject btnRoot =UICommon.CreateUIElementRoot("TextEx", w, h);
        // 添加脚本
        btnRoot.AddComponent<CanvasRenderer>();
        //自动文本框随字体自动变换
        ContentSizeFitter fitter=btnRoot.AddComponent<ContentSizeFitter>();
        fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        Text txt= btnRoot.AddComponent<UITextExtension>();
        txt.text = "New Text";
        txt.alignment = TextAnchor.MiddleCenter;
        UICommon.SetDefaultTextValues(txt);

        // 放入到UI Canvas中
        UICommon.PlaceUIElementRoot(btnRoot, menuCmd);
    }
#endif



}
